<?php
class News extends CI_Model {

	function __construct()
	{
		parent::__construct();
	}
	
	function getList($page){
		$page=$page?$page:0;
		$limit=($page*20).','.'10';
		$query= $this->db->query("select * from ".$this->db->dbprefix."news LIMIT $limit");
		return $query->result();
	}
	
	function getClassListByPid($pid=0){
		$page=isset($_GET['page'])?($_GET['page']-1):0;
		$offset=15;
		
		$limit=$page*$offset.','.$offset;
		//echo $limit;
		if($pid)
			$this->db->where('tid_p',$pid);
		$this->db->from('news');
		
		$this->db->limit($offset,$page*$offset);
		$query = $this->db->get();
		//echo $this->db->last_query();
		$list= $query->result();
		
		
		
		//获取分页字符串
		if($pid)
			$this->db->where('tid_p',$pid);
		$this->db->from('news');
		$total = $this->db->count_all_results();
		
		$this->load->library('pagination');
		$pageHtml=$this->pagination->create_links($total);
		
		return array($list,$pageHtml);
	}
	
	function getInfoById($id)
    {
		$this->db->where('id',$id);
		$query = $this->db->get('news');
		//var_dump($query->result());
		$rs=$query->result();
		if($rs)
        	return $rs[0];
		else 	
			return false;
		//echo 11111111111111;
    }
}